﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChuanYe.WorkLogManagement.Api.Models;
using ChuanYe.WorkLogManagement.BLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ChuanYe.WorkLogManagement.Api.Controllers
{
    /// <summary>
    /// 登录接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> Post(LoginRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                var exist = UserInfoBLL.Instance.Get(0, obj.AccountName,string.Empty);
                if (exist == null)
                {
                    result.Status = 0;
                    result.Message = "AccountName Is Exist";
                }
                else if (obj.Password != Convert.ToString(exist.Password))
                {
                    result.Status = 0;
                    result.Message = "Password Incorrect";
                }
                else
                {
                    exist.Password = string.Empty;
                    result.FirstParam = exist;
                    result.Status = 1;
                    result.Message = "Requst Is Success";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "Login Server Error";
                LogHelper.Error(ex.Message);
            }
            return result;
        }

    }
}